<template>
  <div class="step-three">
    <reservePlan :plan="routeParam" />
    <div class="main">
      <el-card style="width:60%;margin-right: .5%;">
        <h2 class="title">优化策略执行列表</h2>
        <div
          v-for="({ strategyName, description }, i) in strateDataList"
          :key="i"
          v-loading="loading"
          class="list-item"
        >
          <el-card
            style="height: 80px"
            :style="{
              'background-color': checkList[i] ? '#DCF3FD' : '#fff',
            }"
          >
            <div class="item-title">{{ strategyName }}</div>
            <div class="item-scene">{{ description }}</div>

          </el-card>
        </div>
      </el-card>
      <el-card style="width:39%;">
        <h2 class="title">决策引擎运行控制</h2>
        <div class="group" style="justify-content: start;">
          <span style="margin:0px 30px;">多线程</span>
          <el-switch
            v-model="multithreading"
            active-color="#13ce66"
            inactive-color="#ff4949"
          />
        </div>
        <div class="group">
          <span>线程数量：</span>
          <el-select
            v-model="threads"

            filterable
            allow-create
            default-first-option
            placeholder="请选择线程数量"
          >
            <el-option
              v-for="item in threadsOptions"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            />
          </el-select>
        </div>
        <div class="group">
          <span>计算时长：</span>
          <el-select
            v-model="duration"
            filterable
            allow-create
            default-first-option
            placeholder="请选择计算时长"
          >
            <el-option
              v-for="item in durationOptions"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            />
          </el-select>
        </div>
        <div class="group">
          <el-button type="success">开始运行</el-button>
          <el-button type="primary" plain>结束</el-button>
        </div>
      </el-card>
    </div>
    <el-card style="margin:0 5px;">
      <h2 class="title">决策引擎运行控制</h2>
      <el-table
        ref="multipleTable"
        :data="tableData"
        tooltip-effect="dark"
        style="width: 100%"
        border
      >
        <el-table-column
          type="selection"
          width="55"
        />
        <el-table-column
          label="编号"
          width="120"
        >
          <template slot-scope="scope">{{ scope.row.taskId }}</template>
        </el-table-column>
        <el-table-column
          prop="taskName"
          label="方案名称"
          width="120"
        />
        <el-table-column
          prop="description"
          label="方案描述"
          show-overflow-tooltip
        />
        <el-table-column
          prop="addTime"
          label="生成时间"
          show-overflow-tooltip
        />
        <el-table-column
          prop="taskState"
          label="仿真推演验证"
          show-overflow-tooltip
        />
        <el-table-column label="详情">
          <template slot-scope="scope">
            <el-button
              size="mini"
              type="primary"
              @click="handleEdit(scope.$index, scope.row)"
            >详情</el-button>

          </template>
        </el-table-column>
      </el-table>
    </el-card>
    <div class="btn-group">
      <el-button style="width:300px;" @click="goUp">上一步</el-button>
      <el-button type="primary" style="width:300px;" @click="goNext">仿真推演验证</el-button>
    </div>
  </div>
</template>
<script>
import reservePlan from '@/components/createPlan/reservePlan'
import { usertaskstrategy, strategyTask } from '@/api/decision/task'
export default {
  components: {
    reservePlan: reservePlan
  },
  data() {
    return {
      loading: false,
      tableData: [],
      strateDataList: [],
      multithreading: false,
      threads: '0',
      duration: '0',
      threadsOptions: [{
        value: '0',
        label: '5'
      }, {
        value: 'CSS',
        label: '2'
      }, {
        value: 'JavaScript',
        label: '1'
      }],
      durationOptions: [{
        value: '0',
        label: '5s'
      }, {
        value: 'CSS',
        label: '2s'
      }, {
        value: 'JavaScript',
        label: '1s'
      }]
    }
  },
  created() {
    const planParam = JSON.parse(localStorage.getItem('planParam'))
    if (planParam) {
      this.routeParam = planParam
      this.tableData.push(this.routeParam)
      this.getStrategyTask()
    }
  }, methods: {
    /**
     * 根据预案查询下面的策略id
     */
    getStrategyTask() {
      const taskId = this.routeParam.taskId
      this.loading = true
      this.checkList = []
      strategyTask(taskId).then((response) => {
        this.strateDataList = response.rows
        this.loading = false
      })
    },
    goUp() {
      this.$router.go(-1)
    },
    goNext() {
      this.$router.push({ path: '4' })
    }
  }
}
</script>
<style lang="scss" scoped>
.step-three{
  width: 100%;
  padding: 10px;
}
.main{
  margin: 10px 0;
  display: flex;
  justify-content: center;
  width: 100%;
  .group{
   width: 400px; margin:20px auto;
   display: flex;
   justify-content: center;
   span{
    margin: 5px 10px;
    width: 100px;
    text-align: right;
    // margin-right: 10px;
   }
  }
  .list-item{
    margin-bottom: 15px;
    .item-title{
      font-size: 18px;
      font-weight: 600;
    }
    .item-scene{
       font-size: 16px;
    }
  }
}
 .title{
    text-align: center;
    font-weight: 600;
    font-size: 20px;
  }
  .btn-group{
    display: flex;
    margin-top: 15px;
    justify-content: center;
  }
</style>
